//使用pinia 创建一个user 模块进行状态管理
import { defineStore } from "pinia";
//创建store
export const useUserStore = defineStore("user", {
  state:()=>({
      //定义数据源
      token: localStorage.getItem('token') || "",
      // 主题风格
      theme: localStorage.getItem('theme') || "dark",
      // 语言
      lang: localStorage.getItem('lang') || "zh-cn",
      // 用户信息
      UserInfo:{name:"张三"}
  }),
  //执行修改状态
  actions: {
    saveToken(args: string) {
      this.token = args;
      localStorage.setItem('token', args);
    },
    saveTheme(theme: string) {
      this.theme = theme;
      localStorage.setItem('theme', theme);
    },
    saveLang(lang: string) {
      this.lang = lang;
      localStorage.setItem('lang', lang);
    },
    // 修改用户详情
    UpdataUserInfo(data:any) {
      this.UserInfo = data
    }
  },
  //属性计算
  getters: {},
  // 不生效
  persist: {
    pick: ['theme', 'lang', 'token'],
  },
});